package com.tqyan.model.dto.paper;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @description Chat转换、处理大纲
 * <p> <功能详细描述> </p>
 *
 * @author 陈晨
 * @date 2023/4/10 16:55
 */
@Data
public class ConvertOutlineDTO implements Serializable {
    private static final long serialVersionUID = -1421592556180980021L;

    /** 一级标题 */
    private String first;
    /** 二级标题集合 */
    private List<String> secondList;

    public ConvertOutlineDTO() {
        this.secondList = new ArrayList<>();
    }

    /**
     * @description 转换Chat回复大纲
     * <p> <功能详细描述> </p>
     *
     * @author 陈晨
     * @date 2023/5/15 21:48
     */
    public static List<ConvertOutlineDTO> convertChatOutline(List<ChatOutlineDTO> chatOutlineList) {
        List<ConvertOutlineDTO> outlineList = new ArrayList<>();
        for (ChatOutlineDTO chatOutline : chatOutlineList) {
            if (null == chatOutline) {
                continue;
            }
            outlineList.add(new ConvertOutlineDTO());
            ConvertOutlineDTO outline = outlineList.get(outlineList.size() - 1);
            if (StringUtils.isBlank(chatOutline.getFirst())) {
                List<String> list = new ArrayList<>(Arrays.asList(chatOutline.getSubList().get(0)));
                outline.setFirst(list.remove(0));
                outline.setSecondList(list);
                continue;
            }
            if (StringUtils.isNotBlank(chatOutline.getSecond())) {
                outline.setFirst(chatOutline.getFirst());
                outline.setSecondList(Arrays.asList(chatOutline.getSubList().get(0)));
                continue;
            }
            outline.setFirst(chatOutline.getFirst());
            List<String> seconds = new ArrayList<>();
            for (String[] item : chatOutline.getSubList()) {
                seconds.add(item[0]);
            }
            outline.setSecondList(seconds);
        }
        return outlineList;
    }

}


